package com.example.demo.controller;

import com.example.demo.service.StoreAdminService;
import com.example.demo.utils.ApiResponse;
import com.example.demo.utils.StoreAdmin;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class StoreAdminController {
    @Autowired
    private StoreAdminService storeAdminService;

    @PostMapping("/adminLogin")
    public ApiResponse storeAdminLogin(@RequestBody StoreAdmin loginStoreAdmin) {
        return storeAdminService.storeAdminLogin(loginStoreAdmin.getStoreAdminID(), loginStoreAdmin.getStoreAdminPassword());
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "Token for authentication", required = true, dataType = "string", paramType = "header")
    })
    @GetMapping("/admin/storeReservation")
    public ApiResponse getStoreReservation(@RequestHeader("token") String token) {
        return storeAdminService.getStoreReservation(token);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "Token for authentication", required = true, dataType = "string", paramType = "header")
    })
    @GetMapping("/admin/storeCarCount")
    public ApiResponse getStoreCarCount(@RequestHeader("token") String token) {
        return storeAdminService.getStoreCarCount(token);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "Token for authentication", required = true, dataType = "string", paramType = "header")
    })
    @GetMapping("/admin/storeCar")
    public ApiResponse getStoreCar(@RequestHeader("token") String token) {
        return storeAdminService.getStoreCar(token);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "Token for authentication", required = true, dataType = "string", paramType = "header")
    })
    @PutMapping("/admin/storeReservation/{reservationID}/{userID}")
    public ApiResponse confirmStoreReservation(@RequestHeader("token") String token, @PathVariable String reservationID, @PathVariable String userID) {
        return storeAdminService.confirmStoreReservation(token, reservationID, userID);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "Token for authentication", required = true, dataType = "string", paramType = "header")
    })
    @PostMapping("/admin/transfers/{carModelID}")
    public ApiResponse requestCarTransfer(@RequestHeader("token") String token, @PathVariable String carModelID) {
        return storeAdminService.requestCarTransfer(token, carModelID);
    }

    @ApiOperation(value = "还车操作", notes = "根据reservationID进行还车操作，更新订单状态和车辆状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "Token for authentication", required = true, dataType = "string", paramType = "header")
    })
    @PutMapping("/admin/returnCar/{reservationID}")
    public ApiResponse returnCar(@RequestHeader("token") String token, @PathVariable String reservationID) {
        return storeAdminService.returnCar(token, reservationID);
    }
}
